package 剑指offer;

public class M8 {
    public int minSubArrayLen(int target, int[] nums) {
        int[] data=new int[nums.length+1];
        for (int i = 0; i < nums.length; i++) {
            data[i+1]=nums[i]+data[i];
        }
        int min_k=Integer.MAX_VALUE;
        int i=0;
        int j=0;
        while (j<data.length-1) {
            j++;
            while(i<j&&data[j]-data[i]>=target) {
                min_k=Math.min(min_k,j-i);
                i++;
            }
        }
        return min_k==Integer.MAX_VALUE?0:min_k;
    }
}
